package cn.iocoder.yudao.module.polling.controller.admin.pollingprojectsta;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.polling.controller.admin.pollingprojectsta.vo.*;
import cn.iocoder.yudao.module.polling.dal.dataobject.pollingprojectsta.PollingProjectStaDO;
import cn.iocoder.yudao.module.polling.convert.pollingprojectsta.PollingProjectStaConvert;
import cn.iocoder.yudao.module.polling.service.pollingprojectsta.PollingProjectStaService;

@Api(tags = "管理后台 - 项目标准关联")
@RestController
@RequestMapping("/abu/polling-project-sta")
@Validated
public class PollingProjectStaController {

    @Resource
    private PollingProjectStaService pollingProjectStaService;

    @PostMapping("/create")
    @ApiOperation("创建项目标准关联")
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:create')")
    public CommonResult<Integer> createPollingProjectSta(@Valid @RequestBody PollingProjectStaCreateReqVO createReqVO) {
        return success(pollingProjectStaService.createPollingProjectSta(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新项目标准关联")
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:update')")
    public CommonResult<Boolean> updatePollingProjectSta(@Valid @RequestBody PollingProjectStaUpdateReqVO updateReqVO) {
        pollingProjectStaService.updatePollingProjectSta(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除项目标准关联")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:delete')")
    public CommonResult<Boolean> deletePollingProjectSta(@RequestParam("id") Integer id) {
        pollingProjectStaService.deletePollingProjectSta(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得项目标准关联")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:query')")
    public CommonResult<PollingProjectStaRespVO> getPollingProjectSta(@RequestParam("id") Integer id) {
        PollingProjectStaDO pollingProjectSta = pollingProjectStaService.getPollingProjectSta(id);
        return success(PollingProjectStaConvert.INSTANCE.convert(pollingProjectSta));
    }

    @GetMapping("/list")
    @ApiOperation("获得项目标准关联列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:query')")
    public CommonResult<List<PollingProjectStaRespVO>> getPollingProjectStaList(@RequestParam("ids") Collection<Integer> ids) {
        List<PollingProjectStaDO> list = pollingProjectStaService.getPollingProjectStaList(ids);
        return success(PollingProjectStaConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得项目标准关联分页")
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:query')")
    public CommonResult<PageResult<PollingProjectStaRespVO>> getPollingProjectStaPage(@Valid PollingProjectStaPageReqVO pageVO) {
        PageResult<PollingProjectStaDO> pageResult = pollingProjectStaService.getPollingProjectStaPage(pageVO);
        return success(PollingProjectStaConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出项目标准关联 Excel")
    @PreAuthorize("@ss.hasPermission('abu:polling-project-sta:export')")
    @OperateLog(type = EXPORT)
    public void exportPollingProjectStaExcel(@Valid PollingProjectStaExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<PollingProjectStaDO> list = pollingProjectStaService.getPollingProjectStaList(exportReqVO);
        // 导出 Excel
        List<PollingProjectStaExcelVO> datas = PollingProjectStaConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "项目标准关联.xls", "数据", PollingProjectStaExcelVO.class, datas);
    }

}
